#!/usr/bin/env bash
#
# Copyright (c) 2013 Joyent Inc., All rights reserved.
#

. /lib/smartdc/lib_smartdc_scripts.cfg

SCRIPT=/tmp/.operator-script
rm -f $SCRIPT
$MDATA_GET_BIN sdc:operator-script >$SCRIPT
if [[ $? -eq 0 && -f $SCRIPT ]] ; then
    chmod +x $SCRIPT
    lib_smartdc_info "executing sdc:operator-script"
    # TODO: is this abnormally aborting with 'set -e' active?
    $SCRIPT
    operator_script_exit=$?
    if [[ ${operator_script_exit} -gt 0 ]]; then
        lib_smartdc_info "WARNING: operator-script failed: exited \
          ${operator_script_exit}"
    fi
fi
